package com.zx.cloud.controller;

import java.text.SimpleDateFormat;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.zx.cloud.ApiVersion;
import com.zx.cloud.RequestLogging;
import com.zx.cloud.common.filter.CurrentUserId;
import com.zx.cloud.common.filter.IgnoreAuth;
import com.zx.cloud.domain.Dict;
import com.zx.cloud.domain.Edition;
import com.zx.cloud.domain.LianLianParam;
import com.zx.cloud.model.response.ObjectDataResponse;
import com.zx.cloud.service.EditionService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * 
 * @ClassName: LoanOrderController
 * @Description: app版本管理
 * @author: Administrator
 * @date: 2017年10月30日 下午4:18:37
 */
@RestController
@RequestMapping(value = ApiVersion.PROVIDER_V1_PREFIX+"/app")
public class EditionController{
	private static final Logger logger=Logger.getLogger(EditionController.class);
	static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
	@Autowired
	private EditionService editionService;
	
	@IgnoreAuth
	@RequestLogging
	@ApiOperation(value = "获取app版本-andioid", notes = "获取app版本-andioid")
	@RequestMapping(value = "/getAppVersionToAndr", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Edition> getAppVersionToAndr(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId){
		Edition  edition=new Edition();
		edition.setAppType(1);
		 Edition newEdition=editionService.getAppVersion(edition).get(0);
		return new ObjectDataResponse<Edition>(newEdition);
	}
	
	@IgnoreAuth
	@RequestLogging
	@ApiOperation(value = "获取app版本-ios", notes = "获取app版本-ios")
	@RequestMapping(value = "/getAppVersionToIos", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Edition> getAppVersionToIos(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId){
		Edition  edition=new Edition();
		edition.setAppType(2);
		 Edition newEdition=editionService.getAppVersion(edition).get(0);
		return new ObjectDataResponse<Edition>(newEdition);
	}
	
	
	@RequestLogging
	@ApiOperation(value = "获取连连参数", notes = "获取连连参数")
	@RequestMapping(value = "/getLianLianParam", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<LianLianParam> getLianLianParam(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId){
		
		LianLianParam  newEdition=editionService.getLianLianParam();
		return new ObjectDataResponse<LianLianParam>(newEdition);
	}
	
	@RequestLogging
	@ApiOperation(value = "获取支付宝页面开关", notes = "获取支付宝页面开关")
	@RequestMapping(value = "/getPaymentSwitch", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<String> getPaymentSwitch(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId){
		
		String  newEdition=editionService.getPaymentSwitch();
		return new ObjectDataResponse<String>(newEdition);
	}
	
	
	@RequestLogging
	@ApiOperation(value = "支付宝页面开关", notes = "支付宝页面开关")
	@RequestMapping(value = "/switchPayment", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Integer> switchPayment(@ApiParam(hidden=true,name="登录用户ID")@CurrentUserId Long userId,@RequestBody  int type){
		
		int   success=editionService.switchPayment(type);
		return new ObjectDataResponse<Integer>(success);
	}
}
